import pymysql
import pandas as pd
import datetime

import pytz
from quant_researcher.quant.project_tool.time_tool import timestamp_to_str, timestamp_to_datetime

def main():
    db_config = {
        "charset": "utf8",
        "host": "127.0.0.1",
        "port": 3306,
        "user": "root",
        "passwd": "123456"
    }
    conn = pymysql.connect(db='tianzhi', **db_config)
    df = pd.read_sql('select * from test_datetime_timestamp', conn)
    print(df)
    for _, row in df.iterrows():
        print(f"--------------{row['id']}---------------")
        if row['t1'].tzinfo is None:
            print(f"{row['t1']}该时间没有时区")
        if row['t2'].tzinfo is None:
            print(f"{row['t2']}改时间没有时区")
        tmp_t1 = row['t1'].timestamp()
        tmp_t2 = row['t2'].timestamp()
        print(datetime.datetime.fromtimestamp(tmp_t1, tz=pytz.timezone("Asia/Shanghai")))
        print(datetime.datetime.fromtimestamp(tmp_t2, tz=pytz.timezone("Asia/Shanghai")))
        # print(datetime.datetime.fromtimestamp(tmp_t1, tz=datetime.timezone.utc))
        # print(datetime.datetime.fromtimestamp(tmp_t2, tz=datetime.timezone.utc))
        # print(timestamp_to_datetime(tmp_t1))
        # print(timestamp_to_datetime(tmp_t2))
    utc_ts = pd.Timestamp('2023-01-01 12:00:00', tz='UTC')
    if utc_ts.tzinfo is None:
        print("没有时区")
    else:
        print(utc_ts.tzinfo)
main()